package toolkits

import (
	"io/ioutil"
	"net/http"
	"time"
)

func DownloadBin(url, binpath string) (err error) {
	client := &http.Client{Timeout: time.Second * 15}

	req, err1 := http.NewRequest("GET", url, nil)
	if err1 != nil {
		err = err1
		return
	}

	resp, err1 := client.Do(req)
	if err1 != nil {
		err = err1
		return
	}

	content, err1 := ioutil.ReadAll(resp.Body)
	if err1 != nil {
		err = err1
		return
	}

	err = ioutil.WriteFile(binpath, content, 0755)
	return
}
